const Router = require('koa-router')
const { Auth } = require('../../core/middleware/auth')
const { SignIn } = require('../../models/signIn')
const { User } = require('../../models/user')
const router = new Router({
  prefix: '/v1/signIn',
})
router.post('/setSignIn', new Auth().m, async (ctx, next) => {
  // 签到
  const sign = await SignIn.setSignIn(ctx.request.body.time, ctx.auth.id)
  // 签到成功给用户增加积分
  // ctx.request.body.integral
  if (sign) {
    await User.setIntegral(ctx.auth.id, 100)
  }
  if (sign) {
    ctx.body = {
      code: 200,
      data: sign,
    }
  } else {
    ctx.body = {
      code: 409,
      data: [],
      msg: '今天已经签到过啦!!'
    }
  }

})
module.exports = router